import Vue from "vue";
import Vuex from "vuex";
import Axios from "axios"
import { dispatch } from "rxjs/internal/observable/pairs";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    data:[],
    iscla:[],
    isclaid:'',
    isalb:[],
    isdis:'',
    iscom:[],
    isclassid:[],
    /* 获取专辑的id */
    isalbid:'',
    isshowall:[]
  },
  mutations: {
    /* 主页图片不分类 */
    getdata(state,res){
      state.data = res.data.res.vertical
      console.log(state.data)
    },
    /* 分类 */
    getclass(state,res){
      console.log(res)
      state.iscla = res.data.res.category
      console.log(state.iscla)
    },
    /* 每一类的具体内容 */
    getclassid(state,res){
      state.isclaid = res
      console.log(res)
    },
    /* 专辑 */
    getalbum(state,res){
      console.log(res)
      state.isalb = res.data.res.album
      console.log(state.isalb)
    },
    getalbid(state,res){
      console.log(res)
      state.isalbid = res
    } ,
    /* 评论获取id */
    getdiscuss(state,payload){
      state.isdis = payload
      console.log(state.isdis)
    },
    /* 根据id具体显示评论信息 */
    getcomment(state,res){
      console.log(res)
      state.iscom = res.data.res.comment
      console.log(state.iscom)
    },
    /* 分类中每一类的具体内容 */
    getclasid(state,res){
      console.log(res)
      state.isclassid = res.data.res.vertical
      console.log(state.isclassid)
    },
    getshow(state,res){
      console.log(res)
      state.isshowall =res.data.res
      console.log(state.isshowall)
    }
  },
  actions: {
    /* 首页 */
    getdata(context){
      Axios.get('http://service.picasso.adesk.com/v1/vertical/vertical?limit=30&skip=180&adult=false&first=0&order=hot')
      .then((res)=>{
        console.log(res)
        context.commit('getdata',res)
      })
    },
    /* 分类 */
    getclass(context){
      Axios.get('http://service.picasso.adesk.com/v1/vertical/category?adult=false&first=1')
      .then((res)=>{
        console.log(res)
        context.commit('getclass',res)
      })
    },
    /* 专辑 */
    getalbum(context){
      Axios.get('http://service.picasso.adesk.com/v1/wallpaper/album?limit=10&adult=false&first=1&order=hot')
      .then((res)=>{
        console.log(res)
        context.commit('getalbum',res)
      })
    },
    /* 评论 */
    getcomment(context,payload){
      console.log(context);
      console.log(context.state.isdis)
      Axios.get('http://service.picasso.adesk.com/v2/vertical/vertical/'+context.state.isdis+'/comment')
      .then((res)=>{
        context.commit('getcomment',res)
      })
    },
    /* 分类中每一类的具体内容 */
    getclasid(context,payload){
      console.log(context);
      console.log(context.state.isclaid)
      Axios.get('http://service.picasso.adesk.com/v1/vertical/category/'+context.state.isclaid+'/vertical?limit=30&adult=false&first=1&order=new')
      .then((res)=>{
        console.log(res)
        context.commit('getclasid',res)
      })
    },
    /* 专辑中每一个专辑的具体内容 */
    getshow(context){
      Axios.get("http://service.picasso.adesk.com/v1/wallpaper/album/"+context.state.isalbid+"/wallpaper?limit=30&adult=false&first=1&order=new")
      .then((res)=>{
        context.commit("getshow",res)
      })
    }
  }
});
/*  */
/* https://www.easy-mock.com/mock/5a6ac7882d33bf493f881505/hammer/goods-list */